﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.common;
using rock.UI.common;
using rock.UI.fee;

namespace rock.UI.message
{
    public partial class UserControlMessageShaoYajing : UserControl
    {
        DalFEE_SHAOYAJING aDalFEE_SHAOYAJING = new DalFEE_SHAOYAJING();
        int CURRENT_YANINGTYPE = 1;
        int CURRENT_YAJINGMONEY = 0;

        public UserControlMessageShaoYajing()
        {
            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            ViewUtils.setDataGridViewStlye(this.dataGridView1);
        }

        private void UserControlMessageContract_Load(object sender, EventArgs e)
        {
            CURRENT_YANINGTYPE = 1;
            CURRENT_YAJINGMONEY = 0;
            refreshData(1,0);
        }

        

         
        


        private void refreshData(int YajingType, int YajingMoney)
        {
            DataSet ds = aDalFEE_SHAOYAJING.GetShaoYajingNotifyMessage(YajingType, YajingMoney);
            this.dataGridView1.DataSource = ds.Tables[0]; 
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton1.Checked)
            {
                return;
            }
            CURRENT_YANINGTYPE = 1;
            CURRENT_YAJINGMONEY = 0;
            refreshData(1, 0);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton2.Checked)
            {
                return;
            }
            CURRENT_YANINGTYPE = 2;
            CURRENT_YAJINGMONEY = 0;
            refreshData(2, 0);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton3.Checked)
            {
                return;
            }
            CURRENT_YANINGTYPE = 3;
            CURRENT_YAJINGMONEY = 0;
            refreshData(3, 0);
        }

        private void radioButton0_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton0.Checked) {
                return;
            }
            if (this.textBox1.Text == null || this.textBox1.Text.Equals(""))
            {
                return;
            }

            try
            {
                StringUtils.checkIsPositiveInteger(this.textBox1.Text, "固定金额");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
           
            if (int.Parse(this.textBox1.Text) <= 0) {
                MessageBox.Show("固定金额请输入大于0的整数.", "提示");
                return;
            }
            CURRENT_YANINGTYPE = 0;
            CURRENT_YAJINGMONEY = int.Parse(this.textBox1.Text);
            refreshData(0, CURRENT_YAJINGMONEY);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.textBox1.Text == null || this.textBox1.Text.Equals(""))
            {
                return;
            }
            
            this.radioButton1.Checked = false;
            this.radioButton2.Checked = false;
            this.radioButton3.Checked = false;
            this.radioButton0.Checked = true;
            
            try
            {
                StringUtils.checkIsPositiveInteger(this.textBox1.Text, "固定金额");
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "提示");
            }
           
            if (int.Parse(this.textBox1.Text) <= 0)
            {
                MessageBox.Show("固定金额请输入大于0的整数.", "提示");
                return;
            }
            CURRENT_YANINGTYPE = 0;
            CURRENT_YAJINGMONEY = int.Parse(this.textBox1.Text);
            refreshData(0, CURRENT_YAJINGMONEY);
        }

        private void button3_Click(object sender, EventArgs e)
        {
           

            if (dataGridView1.CurrentRow != null)
            {
                String CUSTOM_SEQID = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["CUSTOM_SEQID"].Value.ToString();
                String CONTRACT_SEQID = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["CONTRACT_SEQID"].Value.ToString();
                // this.textBox1.Text = value;
                FormFeeShaoYajingUpdate fu = new FormFeeShaoYajingUpdate();
                fu._ModelFEE_SHAOYAJING.RENT_CONTRACT_SEQID = Convert.ToInt32(CONTRACT_SEQID);
                fu.oneRefreshParentData = oneRefreshParentData;
                fu.ShowDialog(this);


                //注册代理

            }
            else
            {
                MessageBox.Show("请选择要查看的记录.", "提示");
            }
        }

         
         private void oneRefreshParentData(int nouse)
        {
            this.refreshData(CURRENT_YANINGTYPE, CURRENT_YAJINGMONEY);
        }

       
         private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
         {
             setStatusWithDataGrid(this.dataGridView1);
         }

         //合同状态文字化处理 状态
         public void setStatusWithDataGrid(DataGridView dgv)
         {
             for (int a = 0; a < dgv.Rows.Count; a++)
             {

                 try
                 {

                     int status = (int)dgv.Rows[a].Cells["STATUS_INT"].Value;

                     DataGridViewTextBoxCell dgvcc = (DataGridViewTextBoxCell)dgv.Rows[a].Cells["STATUS_STR"];
                     dgvcc.Value = Constant.getByContractStatus(status).Name;
                 }
                 catch (Exception)
                 {

                 }
             }
         }
         private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
         {
             foreach (DataGridViewRow row in dataGridView1.Rows)
             {
                 row.Cells[0].Value = row.Index + 1;
             }
         }
    }
}
